// 
//  EVECDLearnedGroup.m
//  EVE Mac Suite
//
//  Created by Vadim Lozko on 6/22/09.
//  Copyright 2009 __MyCompanyName__. All rights reserved.
//

#import "EVECDLearnedGroup.h"

#import "EVECDCharacter.h"
#import "EVECDSkillGroup.h"
#import "EVECDLearnedSkill.h"
#import "EMSGeneralUtils.h"

@implementation EVECDLearnedGroup 

@dynamic maxLevelSkills;
@dynamic learnedBy;
@dynamic group;
@dynamic learnedSkills;

-(NSNumber*)maxLevelSkills
{
	NSPredicate* levelPredicate = [NSPredicate predicateWithFormat:@"level == 5"];
	NSSet* maxLevelSkillsSet = [self.learnedSkills filteredSetUsingPredicate:levelPredicate];
	return [NSNumber numberWithInt:[maxLevelSkillsSet count]];
}

-(void)setSkillPointsLearned:(NSNumber*)value
{
	//Does nothing.
}

-(NSNumber*)skillPointsLearned
{
	NSExpression* skillPointsLearnedExpression = [NSExpression expressionForKeyPath:@"skillPointsLearned"];
	NSExpression* functionExpression = [NSExpression expressionForFunction:@"sum:" 
																 arguments:[NSArray arrayWithObject:skillPointsLearnedExpression]];
	NSNumber* result = [functionExpression expressionValueWithObject:self.learnedSkills context:nil];
	return result;
}

- (NSManagedObjectID*)displayInfo 
{
	return self.objectID;
}

@end

@implementation EVECDLearnedGroup (BindingsAccessors)

-(NSString*)name
{
	return self.group.name;
}

-(NSSet*)learnedSkillTree
{
	return self.learnedSkills;
}

-(NSArray*)trainedSkillTree
{
	return [self valueForKey:@"trainedSkills"];
}

-(BOOL)isLeaf
{
	return NO;
}

@end